// 引入ElementPlus所有图标
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
import { createApp, nextTick } from 'vue';
import ElementPlusX from 'vue-element-plus-x';
import App from './App.vue';
import router from './routers';
import { guestService } from './services/guestService';
import store from './stores';
import './styles/index.scss';
import './styles/self-markdown.scss';
import 'virtual:uno.css';
import 'element-plus/dist/index.css';
// SVG插件配置
import 'virtual:svg-icons-register';

const app = createApp(App);

// 先注册 Pinia store，确保在其他插件使用前已经初始化
app.use(store);
app.use(router);
app.use(ElMessage);
app.use(ElementPlusX);
// 注册ElementPlus所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

// 应用启动后立即尝试游客登录
app.mount('#app');

// 在应用挂载后稍微延迟进行游客登录，确保store完全初始化
setTimeout(async () => {
  try {
    console.log('应用启动，开始游客登录检查');
    await guestService.autoLoginAsGuest();
  } catch (error) {
    console.error('应用启动时游客登录失败:', error);
  }
}, 100);
